# coding:utf-8
'''
Created on 2015年6月29日

@author: Emrys
'''


class Singleton(type):
    """
        该类是做为元类(metaclass)的

    """

    def __init__(self, *args, **kwargs):
        self.__instance = None
        super().__init__(*args, **kwargs)

    def __call__(self, *args, **kwargs):
        if self.__instance is None:
            self.__instance = super().__call__(*args, **kwargs)
            return self.__instance
        else:
            return self.__instance

# 在类的定义的时候，


class Spam(metaclass=Singleton):

    def __init__(self):
        print('Create Spam')

a = Spam()
b = Spam()
print(a is b, a, b)
